package Aleehot100;

import C017.main;

/**
 * ClassName: c039
 * Package: Aleehot100
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/7/8 08:42
 * @Version 1.0
 * @Since 1.0
 */
public class c039 {
    public static void main(String[] args) {

    }
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public boolean isSymmetric(TreeNode root) {
        if(root == null) {
            return true;
        }
        return check(root.left, root.right);
    }

    private boolean check(TreeNode n1, TreeNode n2) {
        if(n1 == null && n2 == null) {
            return true;
        }
        if(n1 == null || n2 == null) {
            return false;
        }
        boolean check = check(n1.left, n2.right);
        boolean check1 = check(n1.right, n2.left);
        return n1.val == n2.val && check && check1;
    }


}
